const fp = require("lodash/fp");
const cars = [
    {name:"111",horsepower:40,dollar_value:80,in_stock:true},
    {name:"112",horsepower:41,dollar_value:81,in_stock:true},
    {name:"113",horsepower:42,dollar_value:82,in_stock:false},
    {name:"114",horsepower:43,dollar_value:83,in_stock:true},
    {name:"115",horsepower:44,dollar_value:84,in_stock:false},
]

let _average = function(xs) {
    return fp.reduce(fp.add, 0, xs) / xs.length;
}

// let avarageDollarValue = function(cars) {
//     let dollar_values = fp.map(function(car) {
//         return car.dollar_value;
//     }, cars)
//     return _average(dollar_values);
// }

// console.log(avarageDollarValue(cars));

let avarageDollarValue =  fp.flowRight(fp.curry(_average), fp.map(function(car) {
        return car.dollar_value;
    }));

    console.log(avarageDollarValue(cars));